home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
vidlibp
/
vidgen.frm
< prev
next >
Wrap
Text File
|
1995-05-01
|
9KB
|
280 lines
VERSION 2.00
Begin Form VidGen
BackColor = &H00C0C0C0&
BorderStyle = 1 'Fixed Single
Caption = "Maintain "
ClientHeight = 2205
ClientLeft = 1860
ClientTop = 2265
ClientWidth = 6000
Height = 2610
HelpContextID = 245
Left = 1800
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2205
ScaleWidth = 6000
Top = 1920
Width = 6120
Begin CommandButton cmdDelete
Caption = "De&lete"
Height = 465
HelpContextID = 245
Left = 3060
TabIndex = 7
Top = 1500
Width = 1230
End
Begin CommandButton cmdDone
Cancel = -1 'True
Caption = "&Done"
Height = 465
HelpContextID = 245
Left = 4365
TabIndex = 6
Top = 1500
Width = 1230
End
Begin CommandButton cmdUpdate
Caption = "&Update"
Default = -1 'True
Height = 465
HelpContextID = 245
Left = 1755
TabIndex = 5
Top = 1500
Width = 1230
End
Begin CommandButton cmdAdd
Caption = "&Add"
Height = 465
HelpContextID = 245
Left = 450
TabIndex = 4
Top = 1500
Width = 1230
End
Begin TextBox txtText
BackColor = &H0000FFFF&
DataField = "GenText"
DataSource = "dtaGeneric"
Height = 390
HelpContextID = 245
Left = 1395
MaxLength = 50
TabIndex = 1
Top = 450
Width = 4200
End
Begin TextBox txtCode
BackColor = &H0000FFFF&
DataField = "GenCode"
DataSource = "dtaGeneric"
Height = 390
HelpContextID = 245
Left = 450
MaxLength = 1
TabIndex = 0
Top = 450
Width = 645
End
Begin Data dtaGeneric
Connect = ""
DatabaseName = "C:\VB\VIDLIB\VIDLIB.MDB"
Exclusive = 0 'False
Height = 270
Left = 450
Options = 0
ReadOnly = 0 'False
RecordSource = "Genre"
Top = 975
Width = 5145
End
Begin Label lblText
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Text:"
Height = 195
Left = 1395
TabIndex = 3
Top = 225
Width = 450
End
Begin Label lblCode
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Code:"
Height = 195
Left = 450
TabIndex = 2
Top = 225
Width = 510
End
End
' Subsystem: Edit
' Module: VidGen.Frm
' Date: 01/02/94
' Author: Richard Stauch
' Notes:
' This Generic form serves two tables for editing,
' Genre and Rating. For more details on how this is
' accomplished, see the Form_Load event.
Option Explicit
DefInt A-Z
Sub cmdAdd_Click ()
' Add a new record to the table.
' First, make sure the user can enter new data.
cmdUpdate.Enabled = True
txtCode.Enabled = True
txtText.Enabled = True
' Display the current activity.
dtaGeneric.Caption = "Adding record."
' Add a blank record.
dtaGeneric.Recordset.AddNew
' Set the input focus on the first input-capable field.
txtCode.SetFocus
End Sub
Sub cmdDelete_Click ()
' Delete the current record.
If Not CodeInUse(Left$(txtCode.Text, 1), Generic$) Then
' This code is not in use.
dtaGeneric.Recordset.Delete ' Delete the record.
dtaGeneric.Refresh ' Rebuild the record set.
If dtaGeneric.Recordset.EOF And dtaGeneric.Recordset.BOF Then
' The record set is empty, so disable text boxes and buttons.
cmdUpdate.Enabled = False
cmdDelete.Enabled = False
txtCode.Enabled = False
txtText.Enabled = False
' Notify the user there are no records to edit.
dtaGeneric.Caption = "No valid record."
End If
Else
' Notify user this code is in use.
Beep
GenericMsgBox (MBC_CODEINUSE)
End If
End Sub
Sub cmdDone_Click ()
' Remove the Generic form from the display.
Unload VidGen
End Sub
Sub cmdUpdate_Click ()
' Update the current record.
On Error GoTo UpdateError
If (txtCode.Text <> "") And (txtText.Text <> "") Then
' There are no blanks in key fields, so update the record.
dtaGeneric.Recordset.Update
' Make sure the user can delete records.
cmdDelete.Enabled = True
' Rebuild the record set.
dtaGeneric.Refresh
' Inform the user of the current operation.
dtaGeneric.Caption = "Editing record."
Else
' Inform user that fields cannot be blank.
Beep
GenericMsgBox (MBC_NOBLANKS)
End If
' Set the input focus on the first input-capable field.
txtCode.SetFocus
Exit Sub
UpdateError:
' Inform the user there's a problem with the data.
Beep
GenericMsgBox (MBC_BADDATA)
If dtaGeneric.Caption = "Adding record." Then
' Cancel the Add operation, if it's working.
dtaGeneric.Recordset.AddNew
dtaGeneric.Recordset.Refresh
End If
Exit Sub
End Sub
Function CodeInUse (UseCode As String, CodeField As String) As Integer
' Open the Video table, and search for UseCode.
Dim DB As Database ' Define the database object.
Dim T As Dynaset ' Define the table object.
' Open the current database, (Exclusive = False, Read-Only = True).
Set DB = OpenDatabase(PathName$, False, True)
' Use the Video table.
Set T = DB.CreateDynaset("Video")
' We use the FindFirst method to look up the UseCode,
' then reverse the logic of the NoMatch property.
If CodeField$ = "G" Then
' The CodeField variable indicates (G)enre.
T.FindFirst "GenCode = '" + Left$(UseCode$, 1) + "'"
CodeInUse% = Not T.NoMatch
ElseIf CodeField$ = "R" Then
' The CodeField variable indicates (R)ating.
T.FindFirst "RatCode = '" + Left$(UseCode$, 1) + "'"
CodeInUse% = Not T.NoMatch
Else
' The CodeField variable is invalid.
CodeInUse% = False
End If
' We're finished, so close the database and table.
T.Close
DB.Close
End Function
Sub Form_Load ()
' Load the form, and alter the text fields according to the table
' in use. We do this before the Show method.
' First, make sure the Data control is using the right database.
dtaGeneric.DatabaseName = PathName$
' Set captions for Genre or Rating tables.
If Generic$ = "G" Then
' We're using the Genre table.
VidGen.Caption = VidGen.Caption & "Genre Data"
dtaGeneric.RecordSource = "Genre"
txtCode.DataField = "GenCode"
txtText.DataField = "GenText"
ElseIf Generic$ = "R" Then
' We're using the Rating table.
VidGen.Caption = VidGen.Caption & "Rating Data"
dtaGeneric.RecordSource = "Rating"
txtCode.DataField = "RatCode"
txtText.DataField = "RatText"
End If
' Refresh the record set.
dtaGeneric.Refresh
' Show the form on the display, so we can set input focus.
VidGen.Show
If dtaGeneric.Recordset.EOF And dtaGeneric.Recordset.BOF Then
' The table is empty, so disable the update function.
cmdUpdate.Enabled = False
cmdDelete.Enabled = False
txtCode.Enabled = False
txtText.Enabled = False
dtaGeneric.Caption = "No valid record."
' The user can still Add records.
cmdAdd.SetFocus
Else
' There are records, so we default to Edit mode.
dtaGeneric.Caption = "Editing